home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / kcl / kcl.lha / c / unixtime.c < prev   
C/C++ Source or Header  |  1987-06-04  |  2KB  |  144 lines

  1. /*
  2. (c) Copyright Taiichi Yuasa and Masami Hagiya, 1984.  All rights reserved.
  3. Copying of this file is authorized to users who have executed the true and
  4. proper "License Agreement for Kyoto Common LISP" with SIGLISP.
  5. */
  6.  
  7. /*
  8.     unixtime.c
  9. */
  10.  
  11. #include "include.h"
  12. #include <sys/types.h>
  13.  
  14. #ifdef BSD
  15. #include <sys/timeb.h>
  16. #include <sys/times.h>
  17. static struct timeb beginning;
  18. #endif
  19.  
  20. #ifdef ATT
  21. #include <sys/times.h>
  22. long beginning;
  23. #endif
  24.  
  25. #ifdef E15
  26. #include <sys/times.h>
  27. long beginning;
  28. #endif
  29.  
  30. #ifdef DGUX
  31.  
  32.  
  33. #endif
  34.  
  35. runtime()
  36. {
  37.     struct tms buf;
  38.  
  39.     times(&buf);
  40.     return(buf.tms_utime * 1000/60);
  41. }
  42.  
  43. object
  44. unix_time_to_universal_time(i)
  45. int i;
  46. {
  47.     object x;
  48.     vs_mark;
  49.  
  50.     vs_push(make_fixnum(24*60*60));
  51.     vs_push(make_fixnum(70*365+17));
  52.     x = number_times(vs_top[-1], vs_top[-2]);
  53.     vs_push(x);
  54.     vs_push(make_fixnum(i));
  55.     x = number_plus(vs_top[-1], vs_top[-2]);
  56.     vs_reset;
  57.     return(x);
  58. }
  59.  
  60. Lget_universal_time()
  61. {
  62.     check_arg(0);
  63.     vs_push(unix_time_to_universal_time(time(0)));
  64. }
  65.  
  66. Lsleep()
  67. {
  68.     object z;
  69.     
  70.     check_arg(1);
  71.     check_type_or_rational_float(&vs_base[0]);
  72.     if (number_minusp(vs_base[0]) == TRUE)
  73.         FEerror("~S is not a non-negative number.", 1, vs_base[0]);
  74.     Lround();
  75.     z = vs_base[0];
  76.     if (type_of(z) == t_fixnum)
  77.         sleep(fix(z));
  78.     else
  79.         for(;;)
  80.             sleep(1000);
  81.     vs_top = vs_base;
  82.     vs_push(Cnil);
  83. }
  84.  
  85. Lget_internal_run_time()
  86. {
  87.     struct tms buf;
  88.  
  89.     check_arg(0);
  90.     times(&buf);
  91.     vs_push(make_fixnum(buf.tms_utime));
  92. }
  93.  
  94. Lget_internal_real_time()
  95. {
  96. #ifdef BSD
  97.     struct timeb buf;
  98.  
  99.     check_arg(0);
  100.     ftime(&buf);
  101.     vs_push(make_fixnum(((buf.time-beginning.time)*1000+
  102.                  (buf.millitm-beginning.millitm))*60/1000));
  103. #endif
  104.  
  105. #ifdef ATT
  106.     check_arg(0);
  107.     vs_push(make_fixnum((time(0) - beginning)*60));
  108. #endif
  109.  
  110. #ifdef E15
  111.     check_arg(0);
  112.     vs_push(make_fixnum((time(0) - beginning)*60));
  113. #endif
  114.  
  115. #ifdef DGUX
  116.  
  117.  
  118. #endif
  119. }
  120.  
  121. init_unixtime()
  122. {
  123. #ifdef BSD
  124.     ftime(&beginning);
  125. #endif
  126. #ifdef ATT
  127.     beginning = time(0);
  128. #endif
  129. #ifdef E15
  130.     beginning = time(0);
  131. #endif
  132. #ifdef DGUX
  133.  
  134. #endif
  135.  
  136.     make_si_special("*DEFAULT-TIME-ZONE*", make_fixnum(TIME_ZONE));
  137.     make_constant("INTERNAL-TIME-UNITS-PER-SECOND", make_fixnum(60));
  138.  
  139.     make_function("GET-UNIVERSAL-TIME", Lget_universal_time);
  140.     make_function("SLEEP", Lsleep);
  141.     make_function("GET-INTERNAL-RUN-TIME", Lget_internal_run_time);
  142.     make_function("GET-INTERNAL-REAL-TIME", Lget_internal_real_time);
  143. }
  144.